<?php
namespace Admin\Controller;
use Think\Controller;
class AuthController extends Controller {
    public function login(){
    	layout(false);
        $this->display();
    }
    public function do_login(){
		$rules = array(
		     array('username','require','用户名必须！'),
		     array('password','require','密码必须！'),
		);
		$user = M("user"); 
		if (!$user->validate($rules)->create()){
		     $this->error($user->getError());
		}else{
		     $username=I('post.username');
		     $password=md5(I('post.password'));
		     $where=array(
		     	'username'=>$username,
		     	'password'=>$password
		     	);
		     $user=M('admin')->where($where)->find();
		     if(!$user){
		     	$this->error('用户名或密码错误');
		     };
		     $_SESSION['admin_is_login']=true;
		     $_SESSION['username']=$username;
		     $this->success("登录成功",U('admin/index/index'));
		    // $_SESSION['user_id']=$user['id'];
		     //$this->redirect('front/index');
		}
	}
	public function logout(){
		session_destroy();
		$this->success('登出成功',U('admin/auth/login'));
	}
}